<template>
  <a-select  :disabled="disabled" :placeholder="placeholder" :value="getValueSting" @change="handleInput">
    <a-select-option v-for="(item, key) in dictOptions" :key="key" :value="item.value">
      <span style="display: inline-block;width: 100%" :title=" item.text || item.label ">
        {{ item.text || item.label }}
      </span>
    </a-select-option>
  </a-select>
</template>

<script>
import { ajaxGetDictItems, getDictItemsFromCache } from '@api/api'
import { getAction } from '@api/manage'

export default {
  name: 'TeachingDepart',
  props: {
    placeholder: String,
    disabled: Boolean,
    value: [String, Number]
  },
  data(){
    return {
      dictOptions: [
      ],
    }
  },
  computed: {
    getValueSting(){
      // update-begin author:wangshuai date:20200601 for: 不显示placeholder的文字 ------
      // 当有null或“” placeholder不显示
      return this.value != null ? this.value.toString() : undefined;
      // update-end author:wangshuai date:20200601 for: 不显示placeholder的文字 ------
    },
  },
  methods:{
    initDictData() {
      //优先从缓存中读取字典配置

      let parameter = {};
      //根据字典Code, 初始化字典数组
      getAction(`/gfxy/common/queryTeachingDepartment`,parameter).then((res) => {
        if (res.success) {
//                console.log(res.result);
          this.dictOptions = res.result;
        }
      })
    },
    handleInput(e='') {
      let val;
      if(Object.keys(e).includes('target')){
        val = e.target.value
      }else{
        val = e
      }
      console.log(val);
      this.$emit('change', val);
    },
  },
  model:{
    prop: 'value',
    event: 'change'
  },
  mounted() {
    this.initDictData();
  }
}
</script>

<style scoped>

</style>